<!-- 审批结果（待确认、待终审） -->
<template>
  <div class="approveCheck">
    <el-form :inline="true" :model="checkForm" label-width="100px" class="demo-ruleForm">
    
        <el-form-item label="审批金额" prop="approvalConclusionDTO.approveAmount"  label-width="150px"  
          >
          <el-input style="width: 300px;" disabled type="number" v-model="checkForm.approvalConclusionDTO.approveAmount"><template slot="append">万</template></el-input>
        </el-form-item>
        <el-form-item label="抵押类型" prop="approvalConclusionDTO.pledgeType"  label-width="150px" style="width: 50%;"
          >
          <DicSelect :disabledFlag="true" dictType = "抵押类型" :dictValue="checkForm.approvalConclusionDTO.pledgeType" v-on:dictValue="checkForm.approvalConclusionDTO.pledgeType = $event"/> 
        </el-form-item>
        <el-form-item label="年限" prop="approvalConclusionDTO.loanTerm"  label-width="150px"
          >
          <el-input disabled style="width: 300px;" type="number" v-model="checkForm.approvalConclusionDTO.loanTerm"><template slot="append">年</template></el-input>
        </el-form-item>
        <el-form-item label="资方" prop="approvalConclusionDTO.capitalSourceId"  label-width="150px" style="width: 50%;"
          >
          <el-select 
              style="min-width:100%;"
              v-model="checkForm.approvalConclusionDTO.capitalSourceId" 
              @change="change"
              disabled
            >
              <el-option v-for="(item) in captialList" value-key="id" :key="item.id" :value="item.id" :label="item.capitalName"></el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="产品名称" prop="approvalConclusionDTO.capitalProductId" label-width="150px" 
          :rules="[{ required: false, message: '请选择产品', trigger: 'change' }]">
          <!-- <el-input style="width: 300px;" type="text" v-model="checkForm.approvalConclusionDTO.capitalProductId"></el-input> -->
          <el-select 
              style="min-width:100%;"
              v-model="checkForm.approvalConclusionDTO.capitalProductId" 
              @change="productChange"
              clearable
              disabled
            >
              <el-option v-for="(item) in productList" value-key="id" :key="item.id" :value="item.id" :label="item.productName"></el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="利率" prop="approvalConclusionDTO.annualInterestRate"  label-width="150px" style="width: 50%;"
          >
          <el-input  style="width: 300px;" disabled type="number" v-model="checkForm.approvalConclusionDTO.annualInterestRate"><template slot="append">%</template></el-input>
        </el-form-item>
        <el-form-item label="还款方式" prop="approvalConclusionDTO.repayMethod"  label-width="150px"
          >
          <DicSelect :disabledFlag="true" dictType = "还款方式" :dictValue="checkForm.approvalConclusionDTO.repayMethod" v-on:dictValue="checkForm.approvalConclusionDTO.repayMethod = $event"/> 
        </el-form-item>
        <el-form-item label="批复时间" prop="approvalConclusionDTO.replyTime" label-width="150px"  
          >
            <el-input disabled  style="width: 300px;"  v-model="checkForm.approvalConclusionDTO.replyTime" />
        </el-form-item>
        <!-- <el-form-item label="抵押率" prop="approvalConclusionDTO.mortgageRate"  label-width="150px"
          >
          <el-input disabled style="width: 300px;" type="number" v-model="checkForm.approvalConclusionDTO.mortgageRate"><template slot="append">%</template></el-input>
        </el-form-item> -->
        <el-form-item label="带条件批复意见" prop="approvalConclusionDTO.approvalDesc"  label-width="150px" style="width: 50%;"
          >
          <el-input disabled style="width: 300px;" type="textarea" v-model="checkForm.approvalConclusionDTO.approvalDesc"></el-input>
        </el-form-item>
        <!-- <el-form-item label="资料上传" prop="makeContractSignTime"  label-width="150px" style="width: 50%;"
          :rules="[{ required: true, message: '资料不能为空', trigger: 'change' }]">
          <DicSelect  dictType = "产品名称" :dictValue="checkForm.makeContractSignTime" v-on:dictValue="checkForm.makeContractSignTime = $event"/> 
        </el-form-item>
      <el-form-item  label-width="100px"  label=" ">
        <el-button type="primary" @click="submitForm(checkForm)" v-loading="loading">提交</el-button>
      </el-form-item> -->
    </el-form>
  </div>
</template>
<script>
  import { approveCheck, getTaskCandiates, listRedePloyUser,capitalDetail,approvalDetail } from '@/api/project'
import DicSelect from '@/components/select'
import {quertAllCapital,quertChoose} from "@/api/dashboard"
export default {
  props: {
     projectId: undefined,
     taskId: undefined
  },
  components: { DicSelect },
  data() {
    return {
      checkForm: {
        approveStatus: undefined,
        checkerId: undefined,
        opinion: undefined,
        projectId: undefined,
        approvalConclusionDTO:{
          approveAmount: undefined,
          pledgeType:undefined,
          loanTerm: undefined,
          capitalSourceId: undefined,
          annualInterestRate: undefined,
          capitalProductId: undefined,
          approvalType:1,
          repayMethod: undefined,
          mortgageRate: undefined,
          approvalDesc: undefined,
          replyTime:undefined
        }
        
      },
      supplyUserFlag: false,
      supplyUser: [],
      sendCheckPersons: [],
      value: '',
      captialList: [],
      productList:[],
      loading: false
    };
  },
  created() {
    // 初始化数据
    this.getCaptialList();
    this.approvalDetail()
  },
  methods: {
    submitForm() {
      if (this.checkForm.approveStatus == undefined) {
        this.$message.error('请选择办理结果！');
        return;
      }
      this.checkForm.projectId = this.projectId,
      this.checkForm.taskId = this.taskId,
      this.$confirm('你确定要提交吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        // 开始提交信息
        this.loading = true;
        approveCheck(this.checkForm).then((data) => {
          this.loading = false;
          this.$message.success('操作成功');
          this.$store.dispatch("tagsView/delView", this.$route);
          this.$router.go(-1);
        }).catch(() => {
          this.loading = false;
        })
      });
    },
    listRedePloyUser() {
      // 查询数据 构造页面
      listRedePloyUser('审批岗').then((data) => {
        var arr =  data.data;
        arr.forEach((item,index,arr)=> {
          if ("总监" == item.position)
            this.sendCheckPersons.push(item);
        })
      });
    },
    supplyUsers() {
      // 查询数据 构造页面
      getTaskCandiates(this.taskId)
        .then((data) => {
          this.supplyUser = data.data;
          console.log('响应数据:%o', data);
        })
    },
    //节点判断
    handleChange(node) {
      this.restForm();
      this.checkForm.approveStatus = node;
      this.supplyUserFlag = false;
      // 补资料
      if (node === '1') {
        this.opinionFlag = true;
        this.supplyUserFlag = true;
        this.checkForm.opinion = '';
      }
    },
    restForm() {
      this.checkForm = {
        opinion: undefined,
        checkerId: undefined,
        approveStatus: undefined,
         approvalConclusionDTO:{
          approveAmount: undefined,
          pledgeType:undefined,
          loanTerm: undefined,
          capitalSourceId: undefined,
          annualInterestRate: undefined,
          capitalProductId: undefined,
          approvalType:1,
          repayMethod: undefined,
          mortgageRate: undefined,
          approvalDesc: undefined,
          replyTime:undefined
        }
      };
    },
    getCaptialList() {
      quertAllCapital()
        .then(res => {
          this.captialList = res.data
        })
        .catch(() => {
          this.captialList = []
        })
    },
    change(e) {
      capitalDetail({capitalId: this.checkForm.approvalConclusionDTO.capitalSourceId})
        .then(res => {
          let pledgeType = this.checkForm.approvalConclusionDTO.pledgeType;
          this.checkForm.approvalConclusionDTO.productName = res.data.productName;
          this.checkForm.approvalConclusionDTO.annualInterestRate = pledgeType == 1 || pledgeType == 3 ? res.data.oneBetRate : res.data.twoBetRate;
        })
    },
    approvalDetail() {
      approvalDetail({approvalType:1,projectId:this.projectId})
        .then(res => {
          this.checkForm.approvalConclusionDTO = res.data;
           quertChoose({capitalId: this.checkForm.approvalConclusionDTO.capitalSourceId,productType:1})
            .then(res => {
              this.productList = res.data
            })
            .catch(() => {
              this.productList = []
            })
        })
    }
  },
};
</script>

<style>
.approveCheck .el-form-item__content{
  width:300px;
}
</style>